package com.example;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class TableAdd
 */
public class TableAdd extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TableAdd() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		exec(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		exec(request, response);
	}
	public void exec(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.write("<html><head></head><body>print test </body></html>");
		RequestDispatcher view  = request.getRequestDispatcher("tableAdd.jsp");
		String[] movieList = {"Amelie", "Return of the King", "third", "mean girl" };
		List list = new ArrayList();
		list.add("Amelie");
		list.add("mean girl");
		list.add("Return of the King");
		list.add("third");
		request.setAttribute("movieList", movieList);
		request.setAttribute("ObjectList", list);
		
		String[] movieList1 = {"Amelie", "Return of the King", "third", "mean girl" };
		String[] movieList2 = {"Matrix", "Kill Bill", "Boondock Saints" };
		List Mlist = new ArrayList();
		Mlist.add(movieList1);
		Mlist.add(movieList2);
		request.setAttribute("SubList", Mlist);
		
		view.forward(request, response);
		
		
	}

}
